package com.wenhai.spring.aop.pointcut;

import com.wenhai.spring.aop.Guiatrist;
import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

/**
 * {@link org.springframework.aop.aspectj.AspectJExpressionPointcut }
 *
 * @author wenhai
 * @date   2021/5/6
 * @see org.springframework.aop.aspectj.AspectJExpressionPointcut
 */
public class AspectJExpressionPointcutDemo {
    public static void main(String[] args) {
        GrammyGuitarist guiatrist = new GrammyGuitarist();
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression("execution(* sing*(..))");
        Advisor advisor = new DefaultPointcutAdvisor(pointcut, new SimpleAdvice());
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setTarget(guiatrist);
        proxyFactory.addAdvisor(advisor);
        GrammyGuitarist proxy = (GrammyGuitarist) proxyFactory.getProxy();
        proxy.sing("文海");
        proxy.rest();
    }
}
